import Tkinter
import Display
import _feedmanager
import _tagextractor

def viewSetup(self):
    self.screens['mainmenu'] = Tkinter.Frame(self.window,
                                             height = 560,
                                             width = 340)
    self.screens['settings'] = Tkinter.Frame(self.window,
                                             height = 560,
                                             width = 340)
    self.screens['article'] = Tkinter.Frame(self.window,
                                            height = 560,
                                            width = 340)
    for x in self.screens.values():
        x.grid_propagate(0)
    __mainmenu__(self)
    __settings__(self)
    __article__(self)

def __mainmenu__(self):
    ##### MAIN MENU #####
    screenButtons = {}
    self.views['main'] = Display.View(self,self.screens['mainmenu'])
    self.ribbons['main'] = Display.Ribbon(self.screens['mainmenu'],self.views['main'])
    self.ribbons['main'].feeds = Display.Reader.feeds

    #Rows [0,8) (Setting, Title, & Quit):
    F = Tkinter.Frame(self.screens['mainmenu'],height=40,width=40)
    F.pack_propagate(0)
    screenButtons['Options'] = Tkinter.Button(F,
                                              text='Options',
                                              font=('Times',6,'bold'),
                                              command=lambda: self.setScreen('settings'))
    screenButtons['Options'].pack(fill='both',expand=1)
    F.grid(row=0,column=0,rowspan=4,columnspan=4)
    F = Tkinter.Frame(self.screens['mainmenu'],height=80,width=260)
    F.pack_propagate(0)
    Tkinter.Label(F,
                  text='JANUS 0.1',
                  font=('Times',20,'bold'))\
                  .pack(fill='both',expand=1)
    F.grid(row=0,column=4,rowspan=8,columnspan=26)
    F = Tkinter.Frame(self.screens['mainmenu'],height=40,width=40)
    F.pack_propagate(0)
    screenButtons['Quit'] = Tkinter.Button(F,
                                           text='Quit',
                                           font=('Times',10,'bold'),
                                           command=self.window.destroy)
    screenButtons['Quit'].pack(fill='both',expand=1)
    F.grid(row=0,column=30,rowspan=4,columnspan=4)
    #Row [8,10) (Spacer - CheckerBoard):
    for i in range(34):
        if i%2 == 0:
            Tkinter.Frame(self.screens['mainmenu'],bg='black',
                          height=10,width=10)\
                          .grid(row=8,column=i,rowspan=1,columnspan=1)
            Tkinter.Frame(self.screens['mainmenu'],
                          height=10,width=10)\
                          .grid(row=9,column=i,rowspan=1,columnspan=1)
        else:
            Tkinter.Frame(self.screens['mainmenu'],
                          height=10,width=10)\
                          .grid(row=8,column=i,rowspan=1,columnspan=1)
            Tkinter.Frame(self.screens['mainmenu'],bg='black',
                          height=10,width=10)\
                          .grid(row=9,column=i,rowspan=1,columnspan=1)
    #Rows [10,18) (Source Feed Ribbon):
    self.ribbons['main'].grid(row=10,column=1)
    #Rows [18,22) (Spacer):
    Tkinter.Frame(self.screens['mainmenu'],height=40,width=340).grid(row=18,column=0,rowspan=4,columnspan=34)
    #Rows [22,56) (Main Menu View):
    self.views['main'].grid(row=22,column=3)

    self.buttons['main'] = screenButtons

def __settings__(self):
    ##### SETTINGS VIEW #####
    screenButtons = {}
                
    #Rows [0,8) (Main Menu & Quit):
    F = Tkinter.Frame(self.screens['settings'],height=40,width=40)
    F.pack_propagate(0)
    screenButtons['Main'] = Tkinter.Button(F,
                                           text='Main',
                                           font=('Times',10,'bold'),
                                           command=lambda: self.setScreen('mainmenu'))
    screenButtons['Main'].pack(fill='both',expand=1)
    F.grid(row=0,column=0,rowspan=4,columnspan=4)
    F = Tkinter.Frame(self.screens['settings'],height=80,width=260)
    F.pack_propagate(0)
    Tkinter.Label(F,
                  text='Options',
                  font=('Times',20,'bold'))\
                  .pack(fill='both',expand=1)
    F.grid(row=0,column=4,rowspan=8,columnspan=26)
    F = Tkinter.Frame(self.screens['settings'],height=40,width=40)
    F.pack_propagate(0)
    screenButtons['Quit'] = Tkinter.Button(F,
                                           text='Quit',
                                           font=('Times',10,'bold'),
                                           command=self.window.destroy)
    screenButtons['Quit'].pack(fill='both',expand=1)
    F.grid(row=0,column=30,rowspan=4,columnspan=4)
    #Row [8,10) (Spacer - Checkerboard):
    for i in range(34):
        if i%2 == 0:
            Tkinter.Frame(self.screens['mainmenu'],bg='black',
                          height=10,width=10)\
                          .grid(row=8,column=i,rowspan=1,columnspan=1)
            Tkinter.Frame(self.screens['mainmenu'],
                          height=10,width=10)\
                          .grid(row=9,column=i,rowspan=1,columnspan=1)
        else:
            Tkinter.Frame(self.screens['mainmenu'],
                          height=10,width=10)\
                          .grid(row=8,column=i,rowspan=1,columnspan=1)
            Tkinter.Frame(self.screens['mainmenu'],bg='black',
                          height=10,width=10)\
                          .grid(row=9,column=i,rowspan=1,columnspan=1)
    #Row 10 (Spacer):
    Tkinter.Frame(self.screens['settings'],height=10,width=340).grid(row=10,column=0,rowspan=1,columnspan=34)
    #Rows [11,13) (Add feed source):
    F = Tkinter.Frame(self.screens['settings'],height=100,width=180)
    F.pack_propagate(0)
    screenButtons['Manage Sources'] = Tkinter.Button(F,
                                                     text='Manage Sources',
                                                     command=lambda: _feedmanager.run(self))
    screenButtons['Manage Sources'].pack(fill='both',expand=1)
    F.grid(row=11,column=8,rowspan=10,columnspan=18)
    #
    F = Tkinter.Frame(self.screens['settings'],height=350,width=180)
    F.pack_propagate(0)
    screenButtons['Tag Extractor'] = Tkinter.Button(F,
                                                     text='Analysis - Extract Tags',
                                                     command=lambda: _tagextractor.run())
    screenButtons['Tag Extractor'].pack(fill='both',expand=1)
    F.grid(row=21,column=8,rowspan=35,columnspan=18)

    self.buttons['settings'] = screenButtons

def __article__(self):
    ##### ARTICLE VIEW #####
    
    screenButtons = {}
    self.views['article'] = Display.View(self,self.window,size=3)
    self.screens['articleV'] = self.views['article'].frame

    self.ribbons['quickFeeds'] = Display.Ribbon(self.window,self.views['article'],size=3)
    self.ribbons['quickFeeds'].feeds = Display.Reader.feeds
    self.screens['articleFR'] = self.ribbons['quickFeeds'].frame

    self.screens['related'] = Tkinter.Frame(self.window,height=240,width=330)
    Tkinter.Label(self.screens['related'],
                  text='R\ne\nl',
                  font=('Times',8)).grid(row=0,column=0,rowspan=8)
    Tkinter.Label(self.screens['related'],
                  text='E\nd',
                  font=('Times',8)).grid(row=8,column=0,rowspan=8)
    Tkinter.Label(self.screens['related'],
                  text='R\ne\nf',
                  font=('Times',8)).grid(row=16,column=0,rowspan=8)
    self.ribbons['related'] = Display.Ribbon(self.screens['related'],self.views['article'],label='RELATED')
    self.ribbons['related'].feeds = Display.Reader.feeds
    self.ribbons['opinion'] = Display.Ribbon(self.screens['related'],self.views['article'],label='OP-ED')
    self.ribbons['ref'] = Display.Ribbon(self.screens['related'],self.views['article'],label='REFERENCE')
    self.ribbons['related'].grid(row=0,column=1)
    self.ribbons['opinion'].grid(row=8,column=1)
    self.ribbons['ref'].grid(row=16,column=1)
    
    #Rows [0,8) (Headline, Main Menu, & Feed Ribbon):
    F = Tkinter.Frame(self.screens['article'],height=40,width=40)
    F.pack_propagate(0)
    screenButtons['Main'] = Tkinter.Button(F,
                                           text='Main',
                                           font=('Times',10,'bold'),
                                           command=lambda: self.setScreen('mainmenu'))
    screenButtons['Main'].pack(fill='both',expand=1)
    F.grid(row=0,column=0,rowspan=4,columnspan=4)
    F = Tkinter.Frame(self.screens['article'],height=80,width=260)
    F.pack_propagate(0)
    self.rHeadline = Tkinter.Label(F,
                                   text='HEADLINE!',
                                   font=('Times',12,'bold'),
                                   wraplength=250)
    self.rHeadline.pack(fill='both',expand=1)
    F.grid(row=1,column=4,rowspan=8,columnspan=26)
    F = Tkinter.Frame(self.screens['article'],height=40,width=40)
    F.pack_propagate(0)
    screenButtons['Feeds'] = Tkinter.Button(F,
                                            font=('Times',10,'bold'),
                                            command=lambda : self.quickFeeds(),
                                            text='Feeds')
    screenButtons['Feeds'].pack(fill='both',expand=1)
    F.grid(row=0,column=30,rowspan=4,columnspan=4)
    #Rows [8,10) (Spacer - CheckerBoard):
    for i in range(34):
        if i%2 == 0:
            Tkinter.Frame(self.screens['mainmenu'],bg='black',
                          height=10,width=10)\
                          .grid(row=8,column=i,rowspan=1,columnspan=1)
            Tkinter.Frame(self.screens['mainmenu'],
                          height=10,width=10)\
                          .grid(row=9,column=i,rowspan=1,columnspan=1)
        else:
            Tkinter.Frame(self.screens['mainmenu'],
                          height=10,width=10)\
                          .grid(row=8,column=i,rowspan=1,columnspan=1)
            Tkinter.Frame(self.screens['mainmenu'],bg='black',
                          height=10,width=10)\
                          .grid(row=9,column=i,rowspan=1,columnspan=1)
    #Rows [10,53) (Article Text):
    F = Tkinter.Frame(self.screens['article'],height=430,width=320)
    F.pack_propagate(0)
    S = Tkinter.Scrollbar(F)
    S.pack(side='right',fill='y')
    self.rText = Tkinter.Text(F,
                              font=('Times',10),
                              yscrollcommand=S.set,
                              wrap='word')
    self.rText.pack(side='left',fill='both')
    self.rText.insert('1.0','DEFAULT TEXT')
    self.rText.__setitem__('state','disabled')
    F.grid(row=10,column=1,rowspan=43,columnspan=32)
    #Row 53 (Spacer):
    Tkinter.Frame(self.screens['article'],height=10,width=340).grid(row=53,column=0,rowspan=1,columnspan=34)
    #Rows [54,56) (Related Button):
    F = Tkinter.Frame(self.screens['article'],height=20,width=180)
    F.pack_propagate(0)
    screenButtons['Related Articles'] = Tkinter.Button(F,
                                                       text='Related Articles',
                                                       command = lambda : self.relatedFeeds())
    screenButtons['Related Articles'].pack(fill='both',expand=1)
    F.grid(row=54,column=8,rowspan=2,columnspan=18)

    self.buttons['article'] = screenButtons
